/*
 * D.cpp
 *
 *  Created on: 2012-5-30
 *      Author: ncrd
 */


#include <cstdio>
#include <cstring>
#include <cstdlib>

int main (void) {
	int n;
	scanf("%d", &n);
	while (n--) {
		char str[10], *pch;
		scanf("%s", str);
		int h, m;
		pch = strtok(str, ":");
		h = atoi(pch);
		pch = strtok (NULL, ":");
		m = atoi(pch);
		if (m==0) {
			h += 12;
			if (h > 24) h %= 24;
			printf("%d\n", h);
		} else
			printf("0\n");
	}
}
